const mongoose = require('../common/db');

const RecommendSchema = new mongoose.Schema({
    imgUrl: {
        type: String,
        required: true,
        trim: true
    },
    title: {
        type: String,
        required: true,
        minlength: 1,
        maxlength: 255,
        trim: true
    },
    detailUrl: {
        type: String,
        required: true,
        trim: true
    },
}, { timestamps: true });

RecommendSchema.statics.query = async function (condition) {
    return await this.find(condition).exec();
};
// 通过id查找推荐
RecommendSchema.statics.findById = async function (id) {
    return await this.findOne({ _id: id }).exec();
};

// 查看所有推荐
RecommendSchema.statics.findAll = async function () {
    return await this.find().exec();
};

module.exports = mongoose.model('Recommend', RecommendSchema);
